export function parseStyleToObj(input = '') {
  let result = {},
    attributes = input.split(';').filter(v => v);

  for (let i = 0; i < attributes.length; i++) {
    let entry = attributes[i].split(':');
    entry[0] = entry[0].trim()
    entry[1] = entry[1].trim()
    result[entry.splice(0,1)[0]] = entry.join(':');
  }
  return result
}

import toPairs from 'lodash/toPairs'
export function objToStyle(obj) {
  let _pairs = toPairs(obj)
  return _pairs.map(v => {
    return `${v[0]}:${v[1]}`
  }).join(';')
}

export function sstyle(treeNode, desitem, desitemKey, e) {
  let obj = {}
  if (treeNode.attributes[desitem.for]) {
    obj = window.JSON5.parse(treeNode.attributes[desitem.for])
  }
  obj[desitemKey] = e
  treeNode.attributes[desitem.for] = window.JSON5.stringify(obj)
}